/*
https://leetcode.cn/problems/longest-common-subsequence/submissions/584685773/?envType=problem-list-v2&envId=dynamic-programming
1143. 最长公共子序列
*/
class Solution {
public:
    int longestCommonSubsequence(string text1, string text2) {
        int leng1=text1.size(),leng2=text2.size();
        vector<vector<int>>dp(leng1+1,vector<int>(leng2+1));
        for(int i=1;i<=leng1;++i){
            for(int j=1;j<=leng2;++j){
                if(text1[i-1]!=text2[j-1])
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
                else dp[i][j]=dp[i-1][j-1]+1;
            }
        }                    
        return dp[leng1][leng2];
    }
};